package com.julian.delegatePattern.gumballMachine.server;


import java.rmi.RemoteException;

public class WinnerState implements State {
    transient GumballMachine gumballMachine;

    public WinnerState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void ejectQuarter() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void turnCrank() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void dispense() {
        if(gumballMachine.count >= 2){
            System.out.println("WINNER! ADDITONAL GUMBALL");
            gumballMachine.releaseBall();
            gumballMachine.releaseBall();
        }else {
            gumballMachine.releaseBall();
        }
        try {
            if (gumballMachine.getCount() > 0){
                gumballMachine.setState(gumballMachine.getNoQuarterState());
            }else {
                gumballMachine.setState(gumballMachine.getSoldOutState());
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}
